﻿using GalaSoft.MvvmLight;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace WPRD.Models
{
    /// <summary>
    /// 质量控制统计模型
    /// </summary>
    public class QualityControlSummary : ObservableObject
    {
        #region Private Properties
        /// <summary>
        /// 雷达台站
        /// </summary>
        private RadarSite _radarSite;

        /// <summary>
        /// 产品标识（ROBS：实时，HOBS：半小时，OOBS：一小时）
        /// </summary>
        private string _product;

        /// <summary>
        /// 质量控制列表
        /// </summary>
        private List<QualityControl> _qualityControlList;
        #endregion

        #region Creator
        /// <summary>
        /// 构造函数
        /// </summary>
        public QualityControlSummary()
        {
            _qualityControlList = new List<QualityControl>();
        }
        #endregion

        #region Public Properties
        /// <summary>
        /// 雷达台站
        /// </summary>
        public RadarSite RadarSite
        {
            get
            {
                return _radarSite;
            }
            set
            {
                if (value == _radarSite)
                    return;
                _radarSite = value;
                RaisePropertyChanged("RadarSite");
            }
        }

        /// <summary>
        /// 产品标识（ROBS：实时，HOBS：半小时，OOBS：一小时）
        /// </summary>
        public string Product
        {
            get
            {
                return _product;
            }
            set
            {
                if (value == _product)
                    return;
                _product = value;
                RaisePropertyChanged("Product");
            }
        }

        /// <summary>
        /// 质量控制列表
        /// </summary>
        public List<QualityControl> QualityControlList
        {
            get
            {
                return _qualityControlList;
            }
            set
            {
                if (value == _qualityControlList)
                    return;
                _qualityControlList = value;
                RaisePropertyChanged("QualityControlList");
                RaisePropertyChanged("Total");
                RaisePropertyChanged("QC0");
                RaisePropertyChanged("QC1");
                RaisePropertyChanged("QC2");
                RaisePropertyChanged("QC8");
                RaisePropertyChanged("QC0Rate");
                RaisePropertyChanged("QC1Rate");
                RaisePropertyChanged("QC2Rate");
                RaisePropertyChanged("QC8Rate");
            }
        }

        /// <summary>
        /// 总观测组数
        /// </summary>
        public int Total
        {
            get
            {
                return _qualityControlList.Count;
            }
        }

        /// <summary>
        /// 可用
        /// </summary>
        public int QC0
        {
            get
            {
                return _qualityControlList.Count(qc => qc.QualityCode == 0);
            }
        }

        /// <summary>
        /// 可疑
        /// </summary>
        public int QC1
        {
            get
            {
                return _qualityControlList.Count(qc => qc.QualityCode == 1);
            }
        }

        /// <summary>
        /// 错误
        /// </summary>
        public int QC2
        {
            get
            {
                return _qualityControlList.Count(qc => qc.QualityCode == 2);
            }
        }

        /// <summary>
        /// 缺测
        /// </summary>
        public int QC8
        {
            get
            {
                return _qualityControlList.Count(qc => qc.QualityCode == 8);
            }
        }

        /// <summary>
        /// 可用比率
        /// </summary>
        public Decimal QC0Rate
        {
            get
            {
                int totalCount = _qualityControlList.Count;
                if (totalCount == 0)
                    return 0;
                return Convert.ToDecimal(_qualityControlList.Count(qc => qc.QualityCode == 0)) / totalCount;
            }
        }

        /// <summary>
        /// 可疑比率
        /// </summary>
        public Decimal QC1Rate
        {
            get
            {
                int totalCount = _qualityControlList.Count;
                if (totalCount == 0)
                    return 0;
                return Convert.ToDecimal(_qualityControlList.Count(qc => qc.QualityCode == 1)) / totalCount;
            }
        }

        /// <summary>
        /// 错误比率
        /// </summary>
        public Decimal QC2Rate
        {
            get
            {
                int totalCount = _qualityControlList.Count;
                if (totalCount == 0)
                    return 0;
                return Convert.ToDecimal(_qualityControlList.Count(qc => qc.QualityCode == 2)) / totalCount;
            }
        }

        /// <summary>
        /// 缺测比率
        /// </summary>
        public Decimal QC8Rate
        {
            get
            {
                int totalCount = _qualityControlList.Count;
                if (totalCount == 0)
                    return 0;
                return Convert.ToDecimal(_qualityControlList.Count(qc => qc.QualityCode == 8)) / totalCount;
            }
        }
        #endregion
    }
}
